/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sadhar.sipp.anggaranpendapatanuanguktsksasuransimahasiswa;

import java.util.Map;
import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class UnitKerjaPopupWnd extends ClassApplicationModule{
    private Listbox lstboxUnitKerja;
    private AnggaranPendapatanUangUKTSKSAsuransiMahasiswaDAO dao;
    public UnitKerjaPopupWnd(){
        dao = new AnggaranPendapatanUangUKTSKSAsuransiMahasiswaDAOImpl();
    }
    public void onCreate()throws Exception{
        lstboxUnitKerja = (Listbox)getFellow("lstboxUnitKerja");
        loadUnitKerja();
    }

    public void loadUnitKerja()throws Exception{
        lstboxUnitKerja.getItems().clear();
        for(Map m : dao.listUnitKerja()){
            Listitem item = new Listitem();
            item.setValue(m);
            item.appendChild(new Listcell(m.get("Kd_unit_kerja").toString()));
            item.appendChild(new Listcell(m.get("Nama_unit_kerja").toString()));
            lstboxUnitKerja.appendChild(item);

        }
    }

    public void lstboxUnitKerjaOnSelect()throws Exception{
        Map m = (Map)lstboxUnitKerja.getSelectedItem().getValue();
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxKodeUnitKerja = (Textbox)window.getFellow("txtboxKodeUnitKerja");
        Textbox textboxUnitKerja = (Textbox)window.getFellow("textboxUnitKerja");
        textboxUnitKerja.setValue(m.get("Nama_unit_kerja").toString());
        txtboxKodeUnitKerja.setValue(m.get("Kd_unit_kerja").toString());
        this.detach();
    }
}
